package com.yycx.module.bus.provider.handler.haiying.common;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.interceptor.ExportInterceptor;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.bus.client.entity.BusDrugs;
import com.yycx.module.bus.provider.service.hy.HyRemoteOrderService;
import com.yycx.module.system.provider.service.SysCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品列表
 *
 * @author zyf
 */
@Component
public class HyDrugsPageListHandler implements PageInterceptor<BusDrugs>, ExportInterceptor {

    @Autowired
    private HyRemoteOrderService hyRemoteOrderService;

    @Autowired
    private SysCompanyService companyService;

    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        Long companyId = cq.getLong("companyId");
        cq.in("companyId",5L,1018L,100L,1017L);
        //cq.eq(FlymeUtils.isNotEmpty(companyId),"companyId", companyId);
    }

    @Override
    public List<EntityMap> complete(CriteriaQuery<BusDrugs> cq, List<EntityMap> result, EntityMap extra) {
       /* if (FlymeUtils.isNotEmpty(result)) {
            Long companyId = OpenHelper.getCompanyId();
            SysCompany company = companyService.getById(companyId);
            String dbName = company.getBusinessScope();
            ApiAssert.isNotEmpty("账套实例未配置", dbName);
            for (EntityMap entityMap : result) {
                String drugNo = entityMap.get("drugNo");
                if (FlymeUtils.isNotEmpty(drugNo)) {
                    //查询剩余库存数量
                    EntityMap drugMap = hyRemoteOrderService.selectHyDrugSurplusNum(dbName, drugNo);
                    if (FlymeUtils.isNotEmpty(entityMap)) {
                        entityMap.putAll(drugMap);
                    }
                }
            }
        }*/
        return result;
    }
}
